package com.zhangchuchu.neohealth.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhangchuchu.neohealth.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    // 根据用户名查询是否存在
    @Select("SELECT COUNT(*) FROM users WHERE username = #{username}")
    int selectCountByUsername(String username);

    // 根据邮箱查询是否存在
    @Select("SELECT COUNT(*) FROM users WHERE email = #{email}")
    int selectCountByEmail(String email);

    // 根据手机号查询是否存在
    @Select("SELECT COUNT(*) FROM users WHERE phone = #{phone}")
    int selectCountByPhone(String phone);

    // 通过用户名查找用户
    @Select("SELECT * FROM users WHERE username = #{username} LIMIT 1")
    User findByUsername(@Param("username") String username);

    // 通过邮箱查找用户
    @Select("SELECT * FROM users WHERE email = #{email} LIMIT 1")
    User findByEmail(@Param("email") String email);

    // 通过手机号查找用户
    @Select("SELECT * FROM users WHERE phone = #{phone} LIMIT 1")
    User findByPhone(@Param("phone") String phone);
}